home *** CD-ROM | disk | FTP | other *** search
-
- /**************************************************************************
- * *
- * This code is developed by Adam Li. This software is an *
- * implementation of a part of one or more MPEG-4 Video tools as *
- * specified in ISO/IEC 14496-2 standard. Those intending to use this *
- * software module in hardware or software products are advised that its *
- * use may infringe existing patents or copyrights, and any such use *
- * would be at such party's own risk. The original developer of this *
- * software module and his/her company, and subsequent editors and their *
- * companies (including Project Mayo), will have no liability for use of *
- * this software or modifications or derivatives thereof. *
- * *
- * Project Mayo gives users of the Codec a license to this software *
- * module or modifications thereof for use in hardware or software *
- * products claiming conformance to the MPEG-4 Video Standard as *
- * described in the Open DivX license. *
- * *
- * The complete Open DivX license can be found at *
- * http://www.projectmayo.com/opendivx/license.php . *
- * *
- **************************************************************************/
-
- /************************************************************************
- *
- * enc_engine.cpp, Encoder Engines
- *
- * Copyright (C) 2000 DivX Networks
- *
- * Adam Li
- *
- * DivX Advance Research Center <darc@projectmayo.com>
- *
- ************************************************************************/
-
- // This file contains the encoder engine functions. There are starting the
- // encoder engine, converting the image information to the correct format,
- // calling function to compress frames, and ending the encoder engine.
-
- #include "stdafx.h"
- #include "codec.h"
- #include "encore.h"
-
- static FILE *bf;
-
- long codec::encBegin(LPARAM lParam1, LPARAM lParam2)
- {
- BITMAPINFO *lpbiInput;
- BITMAPV4HEADER *infohdr_i;
- ENC_PARAM param1;
-
- lpbiInput = (BITMAPINFO *)lParam1;
- infohdr_i = (BITMAPV4HEADER *)&(lpbiInput->bmiHeader);
-
- param1.x_dim = infohdr_i->bV4Width;
- param1.y_dim = infohdr_i->bV4Height;
- param1.bitrate = bitrate;
- param1.rc_period = rc_period;
- param1.framerate = framerate;
- param1.search_range = search_range;
- param1.max_quantizer = max_quantizer;
- param1.min_quantizer = min_quantizer;
-
- // initialize the encore()
- encore((long)this, ENC_OPT_INIT, ¶m1, NULL);
-
- #ifdef _WRITE_
- bf = fopen("test_alpha4.8.bis", "wb");
- #endif
-
- return ICERR_OK;
- }
-
- long codec::encEnd(LPARAM lParam1, LPARAM lParam2)
- {
- encore((long)this, ENC_OPT_RELEASE, NULL, NULL);
-
- #ifdef _WRITE_
- fclose(bf);
- #endif
-
- return ICERR_OK;
- }
-
- long codec::encEncode(LPARAM lParam1, LPARAM lParam2)
- {
- ICCOMPRESS *icc = (ICCOMPRESS *)lParam1;
- int iccSize = (int)lParam2;
- BITMAPV4HEADER *lpbihdr_i, *lpbihdr_o;
- ENC_FRAME frame;
- ENC_RESULT outflag;
-
- long imgtype, x_dim, y_dim, size, flagmem = 0;
- long enc_opt = 0, result;
-
- lpbihdr_i = (BITMAPV4HEADER *)icc->lpbiInput;
- lpbihdr_o = (BITMAPV4HEADER *)icc->lpbiOutput;
-
- imgtype = getImageType(lpbihdr_i);
- if (imgtype == 0) return ICERR_ERROR;
-
- // call encore()
- x_dim = lpbihdr_i->bV4Width;
- y_dim = lpbihdr_o->bV4Height;
- size = x_dim * y_dim * 3 / 2;
- if ((imgtype == 64) || (imgtype == 65)) { // planer image
- frame.image = icc->lpInput;
- convertImage(icc->lpInput, frame.image, imgtype, x_dim, y_dim);
- } else { // packed image
- if ((frame.image = malloc(size)) == NULL) return ICERR_ERROR;
- flagmem = 1;
- convertImage(icc->lpInput, frame.image, imgtype, x_dim, y_dim);
- }
-
- frame.bitstream = icc->lpOutput;
- frame.length = 0;
-
- // encode the frame with encore
- result = encore((long)this,
- enc_opt,
- &frame,
- &outflag);
-
- // set the length of the output bitstream
- lpbihdr_o->bV4SizeImage = frame.length;
- // set the flag so Windows knows it is a key frame
- *(icc->lpdwFlags) = 0;
- if (outflag.isKeyFrame)
- *(icc->lpdwFlags) = AVIIF_KEYFRAME;
-
- #ifdef _WRITE_
- fwrite(frame.bitstream, 1, frame.length, bf);
- #endif
-
- if (flagmem) free(frame.image);
-
- return ICERR_OK;
- }
-
-